<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>   
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>  
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>       
<c:set var="ctx" value="${pageContext.request.contextPath}"/> 
<%@ taglib prefix="dict" uri="/WEB-INF/tld/dict.tld" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="../include.jsp"/>
<script type="text/javascript">
	
	$(function() {
		itemsMachType = <dict:getDictItem dictCode="DICT_MACH_TYPE"/>;
		initCombogird();
		setCombogridValue();
		$('#proDate').datebox('setValue', formatterDate(new Date()));
		parent.$.messager.progress('close');
		$('#form').form({
			url : '${ctx}/prodMstr/addProdMstr',
			onSubmit : function() {
				validate = $(this).form('validate');	
				if(validate){
					return true;
				}else{
					return false;
				}				
			},
			success : function(result) {
				parent.$.messager.progress('close');
				result = $.parseJSON(result);
				if(result.success) {
					parent.$.modalDialog.openner_dataGrid.datagrid('load');
					parent.$.modalDialog.handler.dialog('close');
					parent.$.messager.alert('系统提示', result.msg, 'info');
				} else {
					parent.$.messager.alert('错误', result.msg, 'error');
				}
			}
		});
	});
		
	//因为grid分页的原因，加载的数据如果不是在第一页，则会不显示textFiedl,而显示了idField
	//因此使用  setValue，加onChange的方式，显示 combogrid的正确值
	function initCombogird(){		
		$('#cc').combogrid({    
		    panelWidth:'50%',
		    panelHeight:'60%',
		    editable:false,
		    idField:'machNum',
		    textField:'machNum',
		    striped:true,
		    nowrap:true,
		    sortName:'MACH_NUM,MACH_TYPE',
			sortOrder:'asc,asc',
			pagination:true,
			rownumbers: true, //是否加行号 
			fitColumns:true,
			//fit:true,
		    url:'${ctx}/machInfo/listMachInfos?activate=1',  
		    columns:[[	
		    	 {field:'machId',checkbox :true},
	    		 {field:'machNum',title:'机台编号',width:50,align:'left'},
	    		 {field:'machName',title:'机台名称',width:50,align:'left'},
	    		 {field:'ip',title:'机台IP',width:50,align:'left'},
	    		 {field:'machType',title:'系统型号',width:50,align:'left',formatter:formatterMachTypye}
			]],			
			toolbar:[
		     	{text: '机台编号:<input type="text" id="machNum"/>'},
		     	{text: '机台名称:<input type="text" id="machName"/>'},
		     	{text: '搜索',iconCls: 'icon-search',
			     	handler: function(){
			     		doSearch();
			     	}
				},
				{text: '重置',iconCls: 'icon-reload',
			     	handler: function(){
			     		reset();
			     	}
				}
			],
			onChange:function(newValue, oldValue){
				$('#_machNum').val(newValue);
			}
		});
	}
	
	function setCombogridValue(){
		var pmId = '${pmId}';
		if(pmId != ""){
			$('#cc').combogrid('setValue', '${prodMstr.machNum}');
		}
	}
	
	function reset(){
		$('#machNum').val("");
		$('#machName').val("");
	}
	
	function doSearch(){
		var _machNum = $('#machNum').val();
		var _machName = $('#machName').val();
		var params = {    
			machNum: _machNum,    
			machName: _machName   
		};
		var url = '${ctx}/machInfo/listMachInfos';
		var grid =  $('#cc').combogrid('grid');
		$(grid).datagrid('options').url= url;
		$(grid).datagrid('load',params);
	}

	function formatterMachTypye(value, row, index){
   		var val =  $.getDictItemText(itemsMachType,value);
   		return val;
   	}
	
	function formatterDate(date) {
        var day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
        var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0"
            + (date.getMonth() + 1);
        return date.getFullYear() + '/' + month + '/' + day;
    };
	
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'center',border:false" title="" style="overflow: hidden;">			
			<form id="form" method="post">
				<input name="pmId" type="hidden" value="${pmId}">
				<input id="_machNum" name="machNum" type="hidden" value="${prodMstr.machNum}">
	            <div style="margin-bottom:5px;padding-top:30px;padding-left:10%">
	                <input labelAlign="right" class="easyui-combobox" id="cc" value="${prodMstr.machNum}" style="width:60%" data-options="label:'机台号:',required:true">
	            </div>	
	            <div style="margin-bottom:5px;padding-left:10%">
	                <input labelAlign="right" class="easyui-textbox" name="itemNo" value="${prodMstr.itemNo}" style="width:60%" data-options="label:'产品名称:',required:true">
	            </div>
	            <div style="margin-bottom:5px;padding-left:10%">
	                <input labelAlign="right" class="easyui-textbox" name="staffId" value="${prodMstr.staffId}" style="width:40%;" data-options="label:'员工工号:',required:true">
	            </div>
	            <div style="margin-bottom:5px;padding-left:10%">
	           		<select class="easyui-combobox" id="workShift" name="shift" validType="selectValueRequired['#workShift']" labelAlign="right" label="班次:"labelPosition="left" editable="false" style="width:40%;">
						<option value="">-请选择-</option>							
						<c:forEach items="${dictShiftItems}" var="item">
							<option value="${item.itemValue}" <c:if test="${prodMstr.shift==item.itemValue}">selected = "selected"</c:if>>${item.itemText}</option>
						</c:forEach>
					</select>
	            </div>	            
	            <div style="margin-bottom:5px;padding-left:10%">
	                <input labelAlign="right" class="easyui-textbox" name="targetQty" value="${prodMstr.targetQty}" style="width:40%;" data-options="label:'目标产量:',required:true,validType:'number'">
	            </div>
	            <div style="margin-bottom:5px;padding-left:10%">
           	      	<c:if test="${not empty prodMstr.pmId}">
						<c:if test="${empty prodMstr.proDate}">
							<input class="easyui-datebox" name="proDate" value="" style="width:40%" labelAlign="right" labelWidth="80px" data-options="label:'生产日期:',editable:false,required:true">
						</c:if>
						<c:if test="${not empty prodMstr.proDate}">
							<input class="easyui-datebox" name="proDate" value="${prodMstr.proDate} " style="width:40%" labelAlign="right" labelWidth="80px" data-options="label:'生产日期:',editable:false,required:true">
						</c:if>
					</c:if>
					<c:if test="${empty prodMstr.pmId}">
						 <input class="easyui-datebox" id="proDate" name="proDate" value="" style="width:40%" labelAlign="right" labelWidth="80px" data-options="label:'生产日期:',editable:false,required:true">
					</c:if>
			    </div>	
	        </form>
		</div>
	</div>
</body>
</html>